Plugins¶
Quick links¶
Concepts¶
- https://sedimental.org/plugin_systems.html
- https://eli.thegreenplace.net/2012/08/07/fundamental-concepts-of-plugin-infrastructures
Python¶
- Pluggy
- Example use: https://docs.datasette.io/en/stable/plugins.html
- iPopo: https://pypi.org/project/iPOPO/
- Plux: https://pypi.org/project/plux/
- DJP: https://simonwillison.net/2024/Sep/25/djp-a-plugin-system-for-django/ (uses pluggy)
- Yantra: https://pypi.org/project/yantra/
- https://github.com/staugur/Flask-PluginKit/
- https://beets.readthedocs.io/en/stable/dev/plugins.html
Javascript¶
Python-Based Plugin Solutions and Architectures¶
Pluggy¶
- Description: Pluggy is a simple, flexible, and powerful plugin system originally developed for pytest. It allows applications to define extensibility points, known as hooks, and enables third-party plugins to add or extend functionality.
- Use Case:
- Ideal for applications requiring an extensible architecture where new functionality can be added dynamically via plugins. Pluggy is well-suited for building pluggable systems for search, storage, and other services, making it a strong candidate for Abilian SBE.
- Existing use cases: Pytest, Django Plugins, Datasette and many more
- Pros:
- Lightweight and easy to integrate into existing systems.
- Well-documented and widely used in major Python projects like pytest.
- Provides a clean, simple API for defining and managing plugins.
- Cons:
- Doesn’t offer advanced lifecycle management features like some other systems.
- Documentation: Pluggy Documentation
Stevedore¶
- Description: Stevedore is a Python library designed to manage dynamic loading of plugins or extensions using setuptools entry points. It allows you to load and manage plugins in a standardized way, based on entry points defined in
setup.py
. - Use Case:
- Useful for applications that need dynamic plugin loading based on Python packaging mechanisms. It integrates well with projects that already use setuptools for package distribution.
- Originally developed for OpenStack.
- Pros:
- Well-integrated with Python packaging tools.
- Provides dynamic loading and entry-point management.
- Easy to extend and integrate into existing applications.
- Cons:
- More focused on entry points; may not offer as much flexibility as more advanced component-based systems.
- Documentation: Stevedore Documentation
Yapsy¶
- Description: Yapsy (Yet Another Plugin SYstem) is a simple and lightweight plugin management system for Python applications. It supports plugin discovery, loading, and interaction via a minimal set of APIs.
- Use Case: Best suited for smaller applications that need a simple plugin system without much overhead.
- Pros:
- Lightweight and straightforward to use.
- Ideal for smaller-scale projects or applications that don’t need complex plugin architectures.
- Cons:
- Lacks advanced features like lifecycle management and dependency injection.
- Documentation: Yapsy Documentation
Flask Extensions¶
- Description: While not a formal plugin system, Flask uses an extensions mechanism that allows developers to add modular functionality to a Flask application. Extensions can be added through
pip
and easily integrated into the core application. - Use Case: Perfect for Flask-based applications, such as Abilian SBE, where functionality like authentication, database integration, and storage can be added modularly.
- Pros:
- Well-suited for Flask-based projects.
- Easy to integrate and manage, with a large ecosystem of existing extensions.
- Cons:
- Flask extensions are specific to Flask and may not generalize well for non-Flask components.
- Documentation: Flask Extensions
Zope Component Architecture (ZCA)¶
- Description: The Zope Component Architecture (ZCA) provides a powerful system for building modular and component-based applications. It is heavily focused on using interfaces and component registrations to achieve loose coupling and modularity.
- Use Case: Ideal for complex applications that require a high degree of modularity and decoupling between components. ZCA allows different implementations to be swapped out or added dynamically.
- Pros:
- Mature and robust architecture for building component-based systems.
- Strong support for interfaces and loose coupling.
- Well-suited for complex, large-scale applications with strong separation of concerns.
- Cons:
- Steeper learning curve and possibly overkill for smaller projects.
- Documentation: Zope Component Architecture
Trac’s Plugin System¶
- Description: Trac, a Python-based project management tool, implements its own plugin system, where most of its functionality is implemented as a plugin. Trac’s plugin system is component-based and modular, allowing administrators to customize their installation extensively.
- Use Case: Best suited for applications that need deep customization, where most core functionalities are implemented as plugins.
- Pros:
- Highly customizable and modular.
- Plugins can modify or extend virtually any part of the application.
- Cons:
- Tied closely to Trac’s ecosystem and specific to Trac’s internal architecture.
- Documentation: Trac Plugin System
PyPlugin¶
- Description: PyPlugin is a lightweight plugin system that allows dynamic discovery and loading of plugins in Python applications. It uses a directory structure or configuration file to find and load plugins.
- Use Case: Suitable for small- to medium-sized projects that need a simple plugin management system without the complexity of more mature systems.
- Pros:
- Lightweight and easy to integrate.
- Minimal learning curve for developers.
- Cons:
- Lacks the advanced features of more mature plugin systems, such as dependency injection or detailed lifecycle management.
- Documentation: PyPlugin
Setuptools Entry Points¶
- Description: Python’s setuptools offers a built-in mechanism for defining entry points, which can be used to expose functionality to other applications or libraries. This is commonly used in plugin systems where external plugins register their capabilities via
setup.py
. - Use Case: Useful for applications that are distributed as Python packages, allowing plugins to register functionality at installation time. Commonly used in systems like Flask, pytest, and Sphinx.
- Pros:
- Seamlessly integrates with Python packaging tools.
- Allows plugin discovery based on installation, with minimal runtime overhead.
- Cons:
- Limited runtime management, as entry points are usually determined at install time rather than dynamically at runtime.
- Documentation: Setuptools Entry Points
PEP 302 - Import Hooks¶
- Description: PEP 302 defines a mechanism for customizing Python’s import system, allowing developers to control how modules are loaded. This can be used to dynamically load plugins at runtime or implement hot-swapping of components.
- Use Case: Suitable for applications that need fine-grained control over how plugins are discovered and loaded at runtime.
- Pros:
- Offers deep control over module imports and loading.
- Useful for creating highly dynamic plugin systems where modules can be loaded or replaced at runtime.
- Cons:
- Complex to implement and maintain; typically overkill for simple plugin systems.
- Documentation: PEP 302 - Import Hooks
Comparison and Discussion¶
Pluggy stands out as an ideal candidate due to its simplicity, flexibility, and the proven success in projects like pytest. Stevedore and Yapsy are also good choices, especially if integrating plugins via Python packaging and entry points is a priority. If a more component-based architecture is needed, Trac Component Architecture (TCA) could provide a robust solution for modular applications. For more lightweight use cases, PyPlugin or Setuptools Entry Points may suffice.
#plugin #pytest
Page last modified: 2024-12-09 23:29:05